//------------Sonic CD BossBody Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 47: TYPE_BOSSBODY

// Function declarations
#function BossBody_Function50
#function BossBody_Function51
#function BossBody_Function52
#function BossBody_Function53
#function BossBody_Function54
#function BossBody_Function55
#function BossBody_Function56
#function BossBody_Function57
#function BossBody_Function58

function BossBody_Function50
	ArrayPos0=Object.Value1
	Object[ArrayPos0].Value5=2
	ArrayPos1=Object[ArrayPos0].Value1
	Object[ArrayPos1].Value2=32768
	Object[ArrayPos1].Value5=16384
	ArrayPos0=Object[ArrayPos1].Value1
	Object[ArrayPos0].Value2=16384
	Object[ArrayPos0].Value5=32768
	ArrayPos0=Object.Value2
	Object[ArrayPos0].Value5=2
	ArrayPos1=Object[ArrayPos0].Value1
	Object[ArrayPos1].Value2=32768
	Object[ArrayPos1].Value5=16384
	ArrayPos0=Object[ArrayPos1].Value1
	Object[ArrayPos0].Value2=16384
	Object[ArrayPos0].Value5=32768
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value1
	SetBit(Object[ArrayPos0].Value4,7,0)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,7,0)
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value2
	SetBit(Object[ArrayPos0].Value4,7,0)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,7,0)
endfunction


function BossBody_Function51
	SetBit(Object[ArrayPos0].Value4,5,1)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,5,1)
	ArrayPos0=Object[ArrayPos1].Value1
	SetBit(Object[ArrayPos0].Value4,5,1)
endfunction


function BossBody_Function52
	SetBit(Object[ArrayPos0].Value4,5,0)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,5,0)
	ArrayPos0=Object[ArrayPos1].Value1
	SetBit(Object[ArrayPos0].Value4,5,0)
endfunction


function BossBody_Function53
	SetBit(Object[ArrayPos0].Value4,4,1)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,4,1)
	ArrayPos0=Object[ArrayPos1].Value1
	SetBit(Object[ArrayPos0].Value4,4,1)
endfunction


function BossBody_Function54
	SetBit(Object[ArrayPos0].Value4,4,0)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,4,0)
	ArrayPos0=Object[ArrayPos1].Value1
	SetBit(Object[ArrayPos0].Value4,4,0)
endfunction


function BossBody_Function55
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value2
	if Object[ArrayPos0].State<5
		Object[ArrayPos0].State=3
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=3
		Object[ArrayPos1].Frame=0
	endif
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value1
	if Object[ArrayPos0].State<5
		Object[ArrayPos0].State=1
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=4
		Object[ArrayPos1].Frame=0
	endif
endfunction


function BossBody_Function56
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value2
	if Object[ArrayPos0].State<5
		Object[ArrayPos0].State=1
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=4
		Object[ArrayPos1].Frame=0
	endif
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value1
	if Object[ArrayPos0].State<5
		Object[ArrayPos0].State=3
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=3
		Object[ArrayPos1].Frame=0
	endif
endfunction


function BossBody_Function57
	ArrayPos0=Object.Value1
	Object[ArrayPos0].Value5=8
	ArrayPos1=Object[ArrayPos0].Value1
	Object[ArrayPos1].Value2=65536
	Object[ArrayPos1].Value5=32768
	ArrayPos0=Object[ArrayPos1].Value1
	Object[ArrayPos0].Value2=49152
	Object[ArrayPos0].Value5=98304
	ArrayPos0=Object.Value2
	Object[ArrayPos0].Value5=8
	ArrayPos1=Object[ArrayPos0].Value1
	Object[ArrayPos1].Value2=65536
	Object[ArrayPos1].Value5=32768
	ArrayPos0=Object[ArrayPos1].Value1
	Object[ArrayPos0].Value2=49152
	Object[ArrayPos0].Value5=98304
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value1
	SetBit(Object[ArrayPos0].Value4,7,1)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,7,1)
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value2
	SetBit(Object[ArrayPos0].Value4,7,1)
	ArrayPos1=Object[ArrayPos0].Value1
	SetBit(Object[ArrayPos1].Value4,7,1)
endfunction


function BossBody_Function58
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value2
	if Object[ArrayPos0].State<5
		Object[ArrayPos0].State=1
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=5
		Object[ArrayPos1].Frame=1
	endif
	ArrayPos0=Object.Value0
	ArrayPos1=Object[ArrayPos0].Value2
	ArrayPos0=Object[ArrayPos1].Value1
	if Object[ArrayPos0].State<5
		Object[ArrayPos0].State=1
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=5
		Object[ArrayPos1].Frame=1
	endif
endfunction


event ObjectMain
	switch Object.State
	case 0
		CallFunction(BossBody_Function50)
		Object.Value6=Object.XPos
		Object.Value6-=7995392
		Object.Value7=Object.XPos
		Object.Value7-=3276800
		Object.State=1
		break
	case 1
		ArrayPos0=Object.Value2
		Object[ArrayPos0].State=8
		ArrayPos1=Object[ArrayPos0].Value1
		Object[ArrayPos1].State=2
		ArrayPos0=Object[ArrayPos1].Value1
		Object[ArrayPos0].State=5
		ArrayPos0=Object.Value1
		CallFunction(BossBody_Function51)
		ArrayPos0=Object.Value1
		GetBit(temp0,Object[ArrayPos0].Value4,4)
		if temp0==0
			Object.YPos+=98304
			ArrayPos0=Object.Value0
			Object[ArrayPos0].YPos+=98304
		else
			SetBit(Object.Value4,0,1)
		endif
		break
	case 2
		ArrayPos0=Object.Value2
		SetBit(Object[ArrayPos0].Value4,0,0)
		ArrayPos0=Object.Value1
		GetBit(temp0,Object[ArrayPos0].Value4,0)
		if temp0==1
			SetBit(Object[ArrayPos0].Value4,0,0)
			if Object[ArrayPos0].State!=6
				if Object[ArrayPos0].State!=5
					Object[ArrayPos0].State=1
					CallFunction(BossBody_Function52)
					ArrayPos0=Object.Value1
					CallFunction(BossBody_Function54)
					ArrayPos0=Object.Value2
					Object[ArrayPos0].State=4
					CallFunction(BossBody_Function52)
					ArrayPos0=Object.Value2
					CallFunction(BossBody_Function53)
					ArrayPos0=Object.Value2
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=1
					ArrayPos0=Object[ArrayPos1].Value1
					Object[ArrayPos0].State=2
					SetBit(Object.Value4,0,1)
				else
					Object[ArrayPos0].State=7
				endif
			else
				Object[ArrayPos0].State=5
			endif
		endif
		break
	case 3
		GetBit(temp0,Object.Value4,1)
		if temp0==0
			SetBit(Object.Value4,1,1)
			CallFunction(BossBody_Function55)
		endif
		ArrayPos0=Object.Value1
		GetBit(temp0,Object[ArrayPos0].Value4,0)
		if temp0==1
			ArrayPos0=Object.Value2
			GetBit(temp0,Object[ArrayPos0].Value4,0)
			if temp0==1
				SetBit(Object.Value4,1,0)
				SetBit(Object.Value4,6,1)
				SetBit(Object.Value4,0,1)
			endif
		endif
		break
	case 4
		ArrayPos0=Object.Value1
		GetBit(CheckResult,Object[ArrayPos0].Value4,0)
		ArrayPos0=Object.Value2
		GetBit(temp0,Object[ArrayPos0].Value4,0)
		CheckResult&=temp0
		if CheckResult==1
			ArrayPos0=Object.Value1
			SetBit(Object[ArrayPos0].Value4,0,0)
			ArrayPos1=Object[ArrayPos0].Value1
			SetBit(Object[ArrayPos1].Value4,0,0)
			ArrayPos0=Object.Value2
			SetBit(Object[ArrayPos0].Value4,0,0)
			ArrayPos1=Object[ArrayPos0].Value1
			SetBit(Object[ArrayPos1].Value4,0,0)
			if Object.XPos<Object.Value6
				Object.Value5=1
			endif
			Object.Value5--
			if Object.Value5==0
				SetBit(Object.Value4,0,1)
				SetBit(Object.Value4,1,0)
			else
				GetBit(temp0,Object.Value4,6)
				if temp0==0
					SetBit(Object.Value4,6,1)
					ArrayPos0=Object.Value1
					Object[ArrayPos0].State=1
					CallFunction(BossBody_Function52)
					ArrayPos0=Object.Value1
					CallFunction(BossBody_Function54)
					ArrayPos0=Object.Value1
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=4
					ArrayPos0=Object.Value2
					Object[ArrayPos0].State=4
					CallFunction(BossBody_Function51)
					ArrayPos0=Object.Value2
					CallFunction(BossBody_Function53)
					ArrayPos0=Object.Value2
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=3
					CallFunction(BossBody_Function55)
				else
					SetBit(Object.Value4,6,0)
					ArrayPos0=Object.Value1
					Object[ArrayPos0].State=4
					CallFunction(BossBody_Function51)
					ArrayPos0=Object.Value1
					CallFunction(BossBody_Function53)
					ArrayPos0=Object.Value1
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=3
					ArrayPos0=Object.Value2
					Object[ArrayPos0].State=1
					CallFunction(BossBody_Function52)
					ArrayPos0=Object.Value2
					CallFunction(BossBody_Function54)
					ArrayPos0=Object.Value2
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=4
					CallFunction(BossBody_Function56)
				endif
			endif
		endif
		break
	case 5
		ArrayPos0=Object.Value1
		GetBit(CheckResult,Object[ArrayPos0].Value4,0)
		ArrayPos0=Object.Value2
		GetBit(temp0,Object[ArrayPos0].Value4,0)
		CheckResult&=temp0
		if CheckResult==1
			GetBit(temp0,Object.Value4,1)
			if temp0==0
				SetBit(Object.Value4,1,1)
				CallFunction(BossBody_Function50)
			else
				ArrayPos0=Object.Value1
				SetBit(Object[ArrayPos0].Value4,0,0)
				ArrayPos1=Object[ArrayPos0].Value1
				SetBit(Object[ArrayPos1].Value4,0,0)
				ArrayPos0=Object.Value2
				SetBit(Object[ArrayPos0].Value4,0,0)
				ArrayPos1=Object[ArrayPos0].Value1
				SetBit(Object[ArrayPos1].Value4,0,0)
				if Object.XPos>=Object.Value7
					Object.Value5=1
				endif
				Object.Value5--
				if Object.Value5==0
					SetBit(Object.Value4,1,0)
					SetBit(Object.Value4,0,1)
				else
					GetBit(temp0,Object.Value4,6)
					if temp0==0
						SetBit(Object.Value4,6,1)
						ArrayPos0=Object.Value1
						Object[ArrayPos0].State=11
						CallFunction(BossBody_Function51)
						ArrayPos0=Object.Value1
						CallFunction(BossBody_Function53)
						ArrayPos0=Object.Value1
						ArrayPos1=Object[ArrayPos0].Value1
						Object[ArrayPos1].State=4
						ArrayPos0=Object.Value2
						Object[ArrayPos0].State=9
						CallFunction(BossBody_Function52)
						ArrayPos0=Object.Value2
						CallFunction(BossBody_Function54)
						ArrayPos0=Object.Value2
						ArrayPos1=Object[ArrayPos0].Value1
						Object[ArrayPos1].State=3
						CallFunction(BossBody_Function55)
					else
						SetBit(Object.Value4,6,0)
						ArrayPos0=Object.Value1
						Object[ArrayPos0].State=9
						CallFunction(BossBody_Function52)
						ArrayPos0=Object.Value1
						CallFunction(BossBody_Function54)
						ArrayPos0=Object.Value1
						ArrayPos1=Object[ArrayPos0].Value1
						Object[ArrayPos1].State=3
						ArrayPos0=Object.Value2
						Object[ArrayPos0].State=11
						CallFunction(BossBody_Function51)
						ArrayPos0=Object.Value2
						CallFunction(BossBody_Function53)
						ArrayPos0=Object.Value2
						ArrayPos1=Object[ArrayPos0].Value1
						Object[ArrayPos1].State=4
						CallFunction(BossBody_Function56)
					endif
				endif
			endif
		endif
		break
	case 6
		GetBit(temp0,Object.Value4,1)
		if temp0==0
			SetBit(Object.Value4,1,1)
			CallFunction(BossBody_Function57)
		endif
		GetBit(temp0,Object.Value4,6)
		if temp0==1
			ArrayPos0=Object.Value1
			ArrayPos1=Object[ArrayPos0].Value1
			Object[ArrayPos1].State=5
			ArrayPos0=Object.Value2
			ArrayPos1=Object[ArrayPos0].Value1
			Object[ArrayPos1].State=6
		else
			ArrayPos0=Object.Value2
			ArrayPos1=Object[ArrayPos0].Value1
			Object[ArrayPos1].State=5
			ArrayPos0=Object.Value1
			ArrayPos1=Object[ArrayPos0].Value1
			Object[ArrayPos1].State=6
		endif
		ArrayPos0=Object.Value1
		GetBit(CheckResult,Object[ArrayPos0].Value4,0)
		ArrayPos0=Object.Value2
		GetBit(temp0,Object[ArrayPos0].Value4,0)
		CheckResult&=temp0
		if CheckResult==1
			ArrayPos0=Object.Value1
			SetBit(Object[ArrayPos0].Value4,0,0)
			ArrayPos1=Object[ArrayPos0].Value1
			SetBit(Object[ArrayPos1].Value4,0,0)
			ArrayPos0=Object.Value2
			SetBit(Object[ArrayPos0].Value4,0,0)
			ArrayPos1=Object[ArrayPos0].Value1
			SetBit(Object[ArrayPos1].Value4,0,0)
			Object.Value5--
			if Object.Value5==0
				SetBit(Object.Value4,1,0)
				SetBit(Object.Value4,0,1)
			else
				GetBit(temp0,Object.Value4,6)
				if temp0==0
					SetBit(Object.Value4,6,1)
					ArrayPos0=Object.Value1
					SetBit(Object[ArrayPos0].Value4,1,0)
					CallFunction(BossBody_Function51)
					ArrayPos0=Object.Value1
					CallFunction(BossBody_Function53)
					ArrayPos0=Object.Value1
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=5
					ArrayPos0=Object[ArrayPos1].Value1
					Object[ArrayPos0].State=1
					ArrayPos0=Object.Value2
					SetBit(Object[ArrayPos0].Value4,1,0)
					Object[ArrayPos0].State=1
					CallFunction(BossBody_Function52)
					ArrayPos0=Object.Value2
					CallFunction(BossBody_Function54)
					ArrayPos0=Object.Value2
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=6
					CallFunction(BossBody_Function58)
				else
					SetBit(Object.Value4,6,0)
					ArrayPos0=Object.Value2
					SetBit(Object[ArrayPos0].Value4,1,0)
					CallFunction(BossBody_Function51)
					ArrayPos0=Object.Value2
					CallFunction(BossBody_Function53)
					ArrayPos0=Object.Value2
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=5
					ArrayPos0=Object[ArrayPos1].Value1
					Object[ArrayPos0].State=1
					ArrayPos0=Object.Value1
					SetBit(Object[ArrayPos0].Value4,1,0)
					Object[ArrayPos0].State=1
					CallFunction(BossBody_Function52)
					ArrayPos0=Object.Value1
					CallFunction(BossBody_Function54)
					ArrayPos0=Object.Value1
					ArrayPos1=Object[ArrayPos0].Value1
					Object[ArrayPos1].State=6
					CallFunction(BossBody_Function58)
				endif
			endif
		endif
		break
	case 7
		if Object.Value3==0
			Object.YPos+=131072
			ObjectTileCollision(0,0,30,0)
			Object.Value3=CheckResult
			Object[-1].YPos=Object.YPos
		endif
		break
	case 8
		Object.Value5--
		if Object.Value5==0
			CallFunction(BossBody_Function50)
			SetBit(Object.Value4,0,1)
			SetBit(Object.Value4,1,0)
		endif
		break

	endswitch
endevent


event ObjectDraw
	DrawSprite(0)
	DrawSprite(1)
endevent


event ObjectStartup
	LoadSpriteSheet("RRZ/Objects.gif")
	SpriteFrame(-36,-32,72,64,271,1)
	SpriteFrame(0,8,24,24,181,35)
endevent

event RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endevent
